/**
 * Created by cj on 18-3-8.
 */

layui.use(['element', 'layer','form','upload'], function(){
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
    form.render();
    element.init();

    //监听折叠
//        element.on('collapse(test)', function(data){
//            layer.msg('展开状态：'+ data.show);
//        });

//监听提交按钮
    form.on('submit(test)', function(data){
        console.log(data);
    });

    var $ = layui.jquery
        ,upload = layui.upload;

    //普通图片上传
    var uploadInst = upload.render({
        elem: '#test1'
        ,url: '../admin/uploadPic'
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            var demand = res.addr;
            $("#demand").val(demand);
        }
    });



});

//alert
function layer_alert(content,yes){
    layui.use('layer', function(){
        var layer = layui.layer;
        layer.alert(content,function(index){
            layer.close(index);
            if(yes!=0){
                window.location.reload();
            }
        });
    });
}
//msg
function layer_msg(content){
    layui.use('layer', function(){
        var layer = layui.layer;
        layer.msg(content);
    });
}